import 'package:flutter/material.dart';

import 'custom.dart';
import 'grid.dart';
import 'list.dart';
import 'model.dart';

/// 推荐使用这个api
class DxQuickPopMenu extends StatelessWidget {
  final double horizontalMargin;
  final double verticalMargin;
  final double arrowSize;
  final Widget child;
  final bool? darkMode;
  final bool useGridView;
  final bool? showArrow;
  final List<DxPopMenuModel> items;
  final dynamic data;
  final DxPopMenuPressType? pressType;

  final DxPopMenuController menuController = DxPopMenuController();

  DxQuickPopMenu({
    Key? key,
    required this.child,
    required this.items,
    this.data,
    this.darkMode,
    this.pressType,
    this.useGridView = true,
    this.showArrow = true,
    this.arrowSize = 14.0,
    this.horizontalMargin = 10.0,
    this.verticalMargin = 10.0,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DxCustomPopMenu(
      menuBuilder: () {
        return useGridView
            ? DxGridPopMenu(
                darkMode: darkMode ?? true,
                items: items,
                controller: menuController,
                data: data,
              )
            : DxListPopMenu(
                darkMode: darkMode ?? true,
                data: data,
                items: items,
                controller: menuController,
              );
      },
      controller: menuController,
      barrierColor: Colors.transparent,
      showArrow: showArrow ?? false,
      pressType: pressType ?? DxPopMenuPressType.singleClick,
      arrowSize: arrowSize,
      horizontalMargin: horizontalMargin,
      verticalMargin: verticalMargin,
      child: child,
    );
  }
}
